Skip to content

Conversation

@orgads
Copy link

@orgads orgads commented Nov 19, 2025

Previously, Terraform would not respect a SIGINT (Ctrl+C) if it occurred during the graph walk phase, specifically if a provider operation was about to start or blocked. This was because the context cancellation was not being propagated effectively to the graph walker or checked before starting new operations.

This commit introduces a StopContext to the Terraform Core Context, which is linked to the operation's stop context. The GraphWalker now checks this context before executing nodes. Additionally, the local backend now properly sets this context and handles early cancellation by returning immediately if the context is cancelled during the plan phase.

A regression test TestLocal_applyStopEarly has been added to verify that the operation aborts immediately when cancelled.

Fixes #31371

Target Release

1.14.x

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

@orgads orgads requested a review from a team as a code owner November 19, 2025 21:06
@crw crw added the bug label Nov 19, 2025
@orgads orgads force-pushed the interrupt branch 3 times, most recently from 740cffc to ed63535 Compare November 20, 2025 07:00
@orgads orgads changed the title Fix: Respect early SIGINT during graph walk fix: respect early SIGINT during graph walk Nov 20, 2025
@orgads orgads marked this pull request as draft November 20, 2025 07:05
@orgads orgads marked this pull request as ready for review November 20, 2025 08:29
@orgads
Copy link
Author

orgads commented Nov 20, 2025

It works for me now. The fix looks kinda ugly though, comments will be appreciated :)
@apparentlymart

Previously, Terraform would not respect a SIGINT (Ctrl+C) if it occurred
during the graph walk phase, specifically if a provider operation was
about to start or blocked. This was because the context cancellation
was not being propagated effectively to the graph walker or checked
before starting new operations.

This commit introduces a StopContext to the Terraform Core Context,
which is linked to the operation's stop context. The GraphWalker now
checks this context before executing nodes. Additionally, the local
backend now properly sets this context and handles early cancellation
by returning immediately if the context is cancelled during the plan
phase.

A regression test TestLocal_applyStopEarly has been added to verify
that the operation aborts immediately when cancelled.

Fixes hashicorp#31371
@crw
Copy link
Contributor

crw commented Nov 20, 2025

Thanks for this submission! I will raise it in the weekly triage.

@orgads
Copy link
Author

orgads commented Nov 20, 2025

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Early SIGINT is not respected if a Terraform Core operation subsequently begins

2 participants